package org.shiro.config.shiro;

import cn.hutool.core.lang.Snowflake;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionIdGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * Shiro.SessionId生成器Snowflake实现
 *
 * @author LiKun
 * @date 2021/11/3 9:07
 */
@Component
public class SnowflakeSessionIdGenerator implements SessionIdGenerator {
    private static final Logger logger = LoggerFactory.getLogger(SnowflakeSessionIdGenerator.class);

    @Resource
    private Snowflake snowflake;

    @Override
    public Serializable generateId(Session session) {
        logger.info("开始生成SessionID");
        return snowflake.nextIdStr();
    }
}
